<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 这是特殊的零一背包：需要定义双重dp数组 */
      var findMaxForm = function (strs, m, n) {
        let dp = new Array(m + 1).fill().map(() => new Array(n + 1).fill(0));
        for (let str of strs) {
          let oneNum = 0;
          let zeroNum = 0;
          for (let s of str) {
            if (s == "0") {
              zeroNum++;
            } else {
              oneNum++;
            }
          }
          for (let i = m; i >= zeroNum; i--) {
            for (let j = n; j >= oneNum; j--) {
              dp[i][j] = Math.max(dp[i][j], dp[i - zeroNum][j - oneNum] + 1);
            }
          }
        }
        return dp[m][n];
      };
    </script>
  </body>
</html>
